package
{
	import flash.display.Sprite;
	import flash.geom.Point;
	
	public class MapLine extends Sprite
	{
		public var distance:Number = 0;
		public var mapLineId:int =0;
		public function MapLine(mapLineID:int,lenght:Number)
		{
			super();
			this.mapLineId = mapLineID;
			distance = lenght;
			drawLine(lenght);
		}
		
		
		private function drawLine(lenght:Number,color:uint = 0x000000):void
		{
			graphics.lineStyle(3,color);
			graphics.moveTo(0,0);
			graphics.lineTo(lenght,0);
			
			drawArrow(new Point(0,0),new Point(lenght,0));
		}
		
		/**
		    * 画箭头 
		    * ---▲
		    * @param start  开始节点
		    * @param end    结束节点
		    * @param color  线条颜色
		    * @param alpha  透明度
		    * @param radius  箭头的大小
		    * 
		    */
		  public function drawArrow(start:Point,end:Point,color:uint=0x000000,alpha:Number=1,radius:Number=8.5):void{
			   var z:Number=Math.sqrt((end.x - start.x) * (end.x - start.x) + (end.y - start.y) * (end.y - start.y));
			   var angle:Number=Math.atan2(end.y - start.y, end.x - start.x);
			   var exAngle:Number=Math.PI * 4.8 / 4;
			   var p1:Point=Point.polar(z, angle);
			   var p2:Point=Point.polar(radius, angle + exAngle);
			   var p3:Point=Point.polar(radius, angle - exAngle);
			   p1.offset(start.x, start.y);
			   p2.offset(p1.x, p1.y);
			   p3.offset(p1.x, p1.y);
			   if(alpha>1) alpha=1;
			   else if(alpha<0) alpha=0;
			   graphics.beginFill(color,alpha);
			   graphics.moveTo(p1.x, p1.y);
			   graphics.lineTo(p2.x, p2.y);
			   graphics.lineTo(p3.x, p3.y);
			   graphics.lineTo(p1.x, p1.y);
			   graphics.endFill();
		  }
		
		
		public function markFindPathLine():void
		{
			this.graphics.clear();
			drawLine(distance,0xff0000);
		
		}
	}
}